/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.base.controller;

import java.util.Map;

import com.dian.common.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.dian.common.controller.AbstractController;
import com.dian.modules.base.entity.CustomerEntity;
import com.dian.modules.base.service.CustomerService;
import com.dian.common.utils.PageUtils;
import com.dian.common.utils.R;

/**
 * 客户信息
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-05-22 01:47:19
 */
@RestController
@Api("客户信息接口")
@RequestMapping("base/customer,fin/customerBalance")
public class CustomerController extends AbstractController {
    @Autowired
    private CustomerService baseCustomerService;


        /**
         * 客户信息列表
         */
        @SysLog("客户信息列表")
        @GetMapping("/list")
        @ApiOperation("客户信息列表")
        @RequiresPermissions("base:customer:list")
        public R list(@RequestParam Map<String, Object> params) {
            PageUtils page = baseCustomerService.queryPage(params);

            return R.ok().put("page", page);
        }

    /**
     * 客户余额
     * @param params
     * @return
     */
    @SysLog("客户余额列表")
    @GetMapping("/balanceList")
    @ApiOperation("客户余额列表")
    @RequiresPermissions("base:customer:list")
    public R balanceList(@RequestParam Map<String, Object> params){
        PageUtils page = baseCustomerService.balanceList(params);
        return R.ok().put("page", page);
    }

        /**
         * 客户信息信息
         */
        @SysLog("客户信息信息")
        @ApiOperation("客户信息信息")
        @GetMapping("/info/{id}")
        @RequiresPermissions("base:customer:info")
        public R info(@PathVariable("id") Long id) {
            CustomerEntity baseCustomer = baseCustomerService.getById(id);


            return R.ok().put("customer", baseCustomer);
        }

        /**
         * 客户信息保存
         */
        @SysLog("客户信息保存")
        @ApiOperation("客户信息保存")
        @PostMapping("/save")
        @RequiresPermissions("base:customer:save")
        public R save(@RequestBody CustomerEntity baseCustomer) {
            baseCustomerService.saveInfo(baseCustomer);

            return R.ok();
        }

        /**
         * 客户信息修改
         */
        @SysLog("客户信息修改")
        @ApiOperation("客户信息修改")
        @PostMapping("/update")
        @RequiresPermissions("base:customer:update")
        public R update(@RequestBody CustomerEntity baseCustomer) {

            baseCustomerService.updateInfo(baseCustomer);

            return R.ok();
        }

        /**
         * 客户信息删除
         */
        @SysLog("客户信息删除")
        @ApiOperation("客户信息删除")
        @PostMapping("/delete")
        @RequiresPermissions("base:customer:delete")
        public R delete(@RequestBody Long[] ids) {
            baseCustomerService.deleteInfo(ids);

            return R.ok();
        }

    }

